﻿<?php


      // /*查询父级为0*/
      $sql = "select * from `power` where `pid`=0";
      $rel =mysqli_query($link,$sql);
      while($d = mysqli_fetch_assoc($rel)){
            $date[] =$d;
      }
      //print_r($date);die;
       /*查询子级*/
      $sqla = "select * from `power` where `pid`!=0";
      $rela =mysqli_query($link,$sqla);
      while($dd = mysqli_fetch_assoc($rela)){
            $datea[] =$dd;
      }
      //print_r($datea);die;


      if(!empty($_POST['username'])&&!empty($_POST['child'])){
        $name = $_POST['username'];
        $power = implode(',',$_POST['child']);
        $status = $_POST['yes'];
        $sql = "insert into `roles` (`name`,`power`,`status`) values('$name','$power',$status)";
        mysqli_query($link,$sql);
        $row = mysqli_affected_rows($link);
        if($row>0){echo "<script>alert('角色添加成功');location.href='index.php?c=role&a=list&admin=1';</script>";}else{echo "<script>alert('角色添加失败');history.go(-1);";}
        //echo $power;die;

      }

		include(CON_VIEW.$q.'/common.html');
?>